package types

import (
	"time"
	"database/sql/driver"
	"strconv"
	"strings"
	"log"
	// "reflect"
)

type Int64Array []int64

func (a Int64Array) Value() (driver.Value, error) {
    var strs []string
    for _, i := range a {
        strs = append(strs, strconv.FormatInt(i, 10))
    }
    return "{" + strings.Join(strs, ",") + "}", nil
}

func (a *Int64Array) Scan(src interface{}) error {
    sourceStr := string(src.([]byte))
    log.Println(sourceStr)
    //a = Int64Array(source)
    return nil
}

type TimeMillisecond int64

func (tm TimeMillisecond) Value() (driver.Value, error) {
	return time.Unix(int64(tm)/1e3, 0), nil
}

func (tm *TimeMillisecond) Scan(src interface{}) error {
    sourceTime := src.(time.Time)
    *tm = TimeMillisecond(sourceTime.Unix() * 1000)
    return nil
}